package cn.yuhh.api.v1.declare;

import cn.yuhh.api.helper.ApiResponse;
import cn.yuhh.api.helper.IDataToMap;
import cn.yuhh.api.service.AbstractApiService;
import cn.yuhh.core.domain.Building;
import cn.yuhh.core.type.Status;
import com.magic.spring.mongo.Mongo;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author ysw
 * @create 2020-02-25-16:13
 * @descreption 建筑列表自动补全
 **/

@Component("listBuild1.0")
public class ListBuildByname extends AbstractApiService {
    @Override
    public Map service(Map request) {
        List<Building> list = Mongo.buildMongo().fuzzy("name", string(request, "name")).eq("status", Status.ACTIVE).limit(10,1).find(Building.class);

        return ApiResponse.success(list, new IDataToMap<Building>() {
            @Override
            public void dataToMap(Map map, Building source) {
                map.put("id", source.getId());
                map.put("name", source.getName());
                map.put("addr", source.getAddr());
                map.put("height", source.getHeight());
                map.put("storey", source.getStorey());
            }
        });
    }
}
